import socket
import threading

serverSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
serverSocket.bind(('127.0.0.1', 8001))
serverSocket.listen(1)
print('Waiting for connection....')


def receive_message(sock, addr):
    while True:
        message = sock.recv(1024)
        print(message.decode('UTF-8'))


while True:
    # first hand shake
    sock, addr = serverSocket.accept()
    print(sock, addr)
    thread = threading.Thread(target=receive_message, args=(sock, addr))
    # receive_message(sock, addr)
    thread.start()
